package com.yzkj.siot.facade.impl;

import com.yzkj.siot.domain.TenantProduct;
import com.yzkj.siot.facade.DeviceFacade;
import com.yzkj.siot.facade.SummaryFacade;
import com.yzkj.siot.service.TenantDeviceDataService;
import com.yzkj.siot.service.TenantDeviceService;
import com.yzkj.siot.service.TenantProductService;
import com.yzkj.siot.vo.RadioDataVO;
import com.yzkj.siot.vo.SummaryIndexTop;
import com.yzkj.siot.vo.SummaryIndexVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class SummaryFacadeImpl implements SummaryFacade {

    @Autowired
    DeviceFacade deviceFacade;

    @Autowired
    TenantProductService productService;

    @Autowired
    TenantDeviceService deviceService;

    @Autowired
    TenantDeviceDataService deviceDataService;

    @Override
    public SummaryIndexVO index() {
        SummaryIndexVO res = new SummaryIndexVO();

        // 顶部四个数据
        SummaryIndexTop top = new SummaryIndexTop();
        // 产品总数
        top.setProductCount(productService.count());
        // 设备总数
        top.setDeviceCount(deviceService.count());
        // 在线设备数量
        top.setOnlineDeviceCount(deviceService.onlineDeviceCount());
        // 本月数据量
        top.setCurMonthDeviceDataCount(deviceDataService.curMonthCount());
        res.setTop(top);

        // 玫瑰图
        RadioDataVO radio = new RadioDataVO();
        List<String> legend = productService.list().stream().map(TenantProduct::getProductName).collect(Collectors.toList());
        radio.setLegend(legend);
        radio.setItems(deviceFacade.queryDeviceOfProductForRadio());
        res.setRadio(radio);

        return res;
    }
}
